package com.example.demo.zb;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.zb.dao.ChannelDO;
import com.example.demo.zb.dao.ChannelDOMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @author linjingze
 * @date 2024/1/22 10:13 AM
 */
@Component
public class InitChannel implements InitializingBean {

    @Autowired
    private ChannelDOMapper channelDOMapper;
    @Override
    public void afterPropertiesSet() throws Exception {
        List<ChannelDO> channelDOS = channelDOMapper.selectList(new QueryWrapper<>());
        if (CollectionUtils.isEmpty(channelDOS)) {
            //init(ExcelReader.XSD_INBOUND_CHANNEL_NAME_LIST, ChannelEnum.HOU);
            //init(ExcelReader.NY_INBOUND_CHANNEL_NAME_LIST, ChannelEnum.NYC);
            //init(ExcelReader.ZJG_INBOUND_CHANNEL_NAME_LIST, ChannelEnum.CHI);
        }
    }

    private void init(List<String> channelList, ChannelEnum channelEnum) {
        for (String s : channelList) {
            ChannelDO channelDO = new ChannelDO();
            channelDO.setName(s);
            channelDO.setType(channelEnum.name());
            channelDOMapper.insert(channelDO);
        }
    }
}
